//
//  HSMessagesTableViewCell.swift
//  HomeSchoolDemo
//
//  Created by rimi on 16/10/10.
//  Copyright © 2016年 黄华强. All rights reserved.
//

import UIKit
///用于回调点赞和回复按钮时间的闭包类型
typealias cellBtnCallBack = (_ cell:UITableViewCell) -> ()

class HSMessagesTableViewCell: UITableViewCell {

    @IBOutlet weak var userType: UILabel!

    @IBOutlet weak var userNameLabel: UILabel!
    @IBOutlet weak var iconImageView: UIImageView!
    
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var dateLabel: UILabel!
    
    @IBOutlet weak var contentLabel: UILabel!
    
    @IBOutlet weak var likeButton: UIButton!
    
    
    @IBOutlet weak var replayBgView: HSReplayView!
    
    @IBOutlet weak var replayViewH: NSLayoutConstraint!
    
    var likeBtnCallback: cellBtnCallBack?
    var replayBtnCallback: cellBtnCallBack?
    //数据模型（消息视图模型）
    
    var messageVM: HSMessagesViewModel? {
        
        didSet{
            
            //设置头像地址
            let iconImageUrl = "http://120.24.57.38/new/zao/" + (messageVM?.message.not_tpath ?? "")
            iconImageView.xx_setImage(urlStr: iconImageUrl, placeholderImage: "boy", size: CGSize(width: 50, height: 50))
            
            userType.text = messageVM?.message.not_courseName
            dateLabel.text = messageVM?.message.not_createDate
            titleLabel.text = messageVM?.message.not_title
            contentLabel.text = messageVM?.message.not_content
            userNameLabel.text = messageVM?.message.not_Name
            
            let likeN = messageVM?.message.likenum ?? 0
            if likeN > 0 {
                likeButton.setTitle("\(likeN)", for: .selected)
                likeButton.isSelected = true
            } else {
                likeButton.isSelected = false
            }
            //传递视图给回复视图
            replayBgView.messageVM = messageVM
            //设置高度
            replayViewH.constant = messageVM?.replayViewH ?? 0
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // 设置圆角
//        iconImageView.layer.cornerRadius = 25
//        iconImageView.layer.masksToBounds = true
        //设置用户类型边框
        userType.layer.cornerRadius = 8
        userType.layer.borderColor = UIColor().colorWithHex(0x00a0e9).cgColor
        userType.layer.borderWidth = 1
    }
    //点赞按钮监听
    @IBAction func likeBtnClicked(_ sender: UIButton) {
        likeBtnCallback?(self)
    }
    //回复按钮监听
    @IBAction func replayBtnClicked(_ sender: UIButton) {
       replayBtnCallback?(self)
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)


    }
    
}
